/*
* Monobit.cpp
* Last edited: 21.07.2014
* Author: David Noack
*/

#include "Monobit.h"
#include "math.h"

//Inittialize the base class with the input data
Monobit::Monobit(bool* bitArray, int bitArraySize) : NistTest(bitArray, bitArraySize){};



double Monobit::execute(int size)
{
	n = size;
	double sn = 0.0;
	double sqrt2 = 1.4142135623730950488016887242097;
	double sobs = 0.0;
	


		//aufaddiere
		for (int i = 0; i < size; i++)
			sn += 2*(int)bitArray[i] - 1;

		sobs = fabs(sn) / sqrt(size);

		p_value = erfc((sobs / sqrt2));

		return p_value;
}
